package com.mj;

import com.mj.entity.Student;
import com.mj.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class Demo {
    public static void main(String[] args) throws IOException {
        //System.out.println("asda");
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
        //System.out.println(sf);
        //读取会话
        SqlSession s = sf.openSession();

        //System.out.println(s);
        //System.out.println(sl);
        StudentMapper sdm = s.getMapper(StudentMapper.class);
        //System.out.println(sdm);
        Student ss = sdm.queryById(10);
        System.out.println(ss);
        s.commit();
        SqlSession si = sf.openSession();
        StudentMapper sim = si.getMapper(StudentMapper.class);
        ss.setName("萧峰");
        sim.update(ss);
        si.commit();
        //实现删除操作
        //int i = sdm.deleteById(25);
        //System.out.println(i);
      // int i = s.delete("deleteById",30);
        //System.out.println(i);
        //实现查询操作 返回List结果
        /*//*List<Student> sts = s.selectList("query");
        System.out.println(sts.size());
        for (Student st : sts) {
           System.out.println(st.getName());
        }*/

    }
}
